const mongoose = require('mongoose');

const schema = new mongoose.Schema({
    username: String,
    password: {
        type: String,
        select: false,
        set(val) {
            return require('bcrypt').hashSync(val, 10);
        }
    },
    profile: {
        url: {type: String, default: ''},
        scale: {type: String, default: 0},
        pos: {
            x: {type: Number, default: 0},
            y: {type: Number, default: 0},
        }
    },
    signature: {type: String, default: '还没有设置个人签名'},
    friends: [{type: mongoose.Schema.Types.ObjectId, ref: 'User'}],
    friendReq: [{type: mongoose.Schema.Types.ObjectId, ref: 'User'}],
    currentMessages: [{
        opposite: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
        content: {type: mongoose.Schema.Types.ObjectId, ref: 'privateMessage'},
        unread: {type: Number, default: 0},
    }],
    groupMessages: [{type: mongoose.Schema.Types.ObjectId, ref: 'groupMessage'}],
    blogs: [{type: mongoose.Schema.Types.ObjectId, ref: 'Blog'}]
})

module.exports = mongoose.model('User', schema);